package algorithm;

import java.util.ArrayList;

/**
 * @Description : 五角数，测试自顶向下的设计方法
 * Created by cyd on 2021-04-25 20:57:28
 */
public class PentagramNumber {
    public static void main(String[] args) {
        pringWuJiaoNum(100);
    }

    private static void pringWuJiaoNum(int length) {
        ArrayList<Integer> list = new ArrayList<>(100);
        for (int i = 1; i <= length; i++) {
            int count = count(i);
            list.add(count);
        }

        print(list);
    }

    private static void print(ArrayList<Integer> list) {
        for (int i = 0; i < list.size(); i++) {
            System.out.printf("%6d ", list.get(i));
            if ((i + 1) % 10 == 0) {
                System.out.println();
            }
        }
    }

    public static int count(int n) {
        return n * (3 * n - 1) / 2;
    }

}
